<extend name="Admin@default/common/dashboard_layout"/>
<block name="content">
<form class="ajax-form" action="" method="post">
    <!-- Content Header (Page header) -->
    <section class="content-header clearfix">
        <h1 class="pull-left">新增用户组</h1>
        <div class="pull-right">
            <button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-save"></i> 提交</button>
        </div>
    </section>

    <!-- Main content -->
    <section class="content" n-id="36">
        <div class="box box-solid">
            <div class="box-body">
                <div class="form-group">
                    <label for="name">用户组名称<span class="required"></span></label>
                    <input type="text" class="form-control" name="name" id="name" required max="12" min="1">
                </div>
                <div class="form-group">
                    <label for="remark">备注:</label>
                    <textarea class="form-control" name="remark" id="remark"></textarea>
                </div>

                <div class="form-group">
                    <label for="">用户组权限：</label>
                    <volist name='module_list' id='module'>
                        <p>{$module.title}</p>
                        <volist name='controller_list' id='controller'>
                            <if condition="($controller['pid'] eq $module['id'])">
                                <table class="table table-bordered action_list">
                                    <tr>
                                        <th><input type="checkbox" class="checkall"> {$controller.title}</th>
                                    </tr>
                                    <tr>
                                        <td>
                                            <volist name='action_list' id='action' >
                                                <if condition="($action['pid'] eq $controller['id'])">
                                                    <label class="margin action-item" for="auth_{$action.id}"><input class="action_item" id="auth_{$action.id}" name="auth[]" value="{$action.id}" type="checkbox"> {$action.title}</label>
                                                </if>
                                            </volist>
                                        </td>
                                    </tr>
                                </table>
                            </if>
                        </volist>
                    </volist>
                </div>
            </div><!-- /.box-body -->
        </div>
    </section><!-- /.content -->
</form>
</block>

<block name="script">
<script type="text/javascript" src="__PUBLIC__/libs/bootstrap-validator/validator.js"></script>
<script type="text/javascript" src="__PUBLIC__/libs/bootstrap-validator/bootstrap-validator.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
    $('input,select,textarea').bs_validator();
    $('table.action_list').each(function(){
        var $allItems = $(this).find('input.action_item');
        var $allItemsChecked = $allItems.filter(':checked');
        if($allItems.length!=0 && ($allItems.length == $allItemsChecked.length)){
            $(this).find('input.checkall').prop('checked',true);
        }
    });
    $('input.checkall').on('change',function(){
        var $allItems = $(this).parents('table.action_list').find('input.action_item');
        if($(this).prop('checked')){
            $allItems.prop('checked',true);
        }
        else{
            $allItems.prop('checked',false);
        }
    });
});

</script>
</block>
